home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume91 / utilitys / beav_132 / part01 / ttyio.c < prev    next >
C/C++ Source or Header  |  1991-11-13  |  3KB  |  203 lines

  1. /*
  2. *
  3. *   MS-DOS terminal I/O.               TTYIO.C
  4. */
  5.  
  6. #include        "def.h"
  7. #ifdef    MSDOS
  8.  
  9.  
  10. void    ttopen ();
  11. void    ttclose (); /* stub */
  12. void    ttputc ();
  13. void    putline ();
  14. void    ttflush (); /* stub */
  15. int     ttkeyready ();
  16. int     ttgetc ();
  17. void    ttraw ();
  18. void    ttcooked ();
  19. void    set_crt_type ();
  20.  
  21. #include    "dos.h"
  22.  
  23. int     slot;
  24. int     scr_type;
  25. #define SCREEN_PORT (video_port)
  26. static int  video_port =
  27. {
  28.     0x1010
  29. };
  30.  
  31. extern  bool    wang_pc;
  32. extern  bool    ibm_pc;
  33. int     nrow;                   /* Terminal size, rows.         */
  34. int     ncol;                   /* Terminal size, columns.      */
  35. int     last_key;
  36.  
  37. /*
  38. * Initialization.
  39. * Almost no operation in MS-DOS.
  40. */
  41. void ttopen ()
  42. {
  43.     if (wang_pc && !ibm_pc)
  44.         set_crt_type ();
  45.     nrow = NROW;
  46.     ncol = NCOL;
  47. }
  48.  
  49. void ttclose ()
  50. {
  51. }
  52. void ttflush ()
  53. {
  54. }
  55. /*
  56. * Write character.
  57. */
  58. void ttputc (c)
  59. {
  60.     bdos (6, c, 0);
  61. }
  62.  
  63. void putline (row, startcol, stringsize, string)
  64. int     row,
  65. startcol,
  66. stringsize;
  67. char   *string;
  68. {
  69.     extern int  tthue;
  70.     unsigned short *screen;
  71.     int     x,
  72.     attribute;
  73.     char    c_row, c_col, i;
  74.     union   REGS    regs;
  75.  
  76.     if (ibm_pc)
  77.     {
  78.         c_row = row - 1;
  79.         c_col = startcol - 1;
  80.         for (i = 0; i < stringsize; i++)
  81.         {
  82.             regs.h.ah = 2;
  83.             regs.h.dh = c_row;
  84.             regs.h.dl= c_col;
  85.             regs.h.bh = 0;
  86.             int86 (0x10, ®s, ®s); /* set cursor position */
  87.  
  88.             if (tthue == CTEXT)
  89.                 regs.h.bl = 0x07;
  90.             if (tthue == CMODE)
  91.                 regs.h.bl = 0x70;
  92.             regs.h.ah = 9;
  93.             regs.h.bh = 0;
  94.             regs.h.al = string[i];
  95.             regs.x.cx= 1;
  96.             int86 (0x10, ®s, ®s); /* set cursor position */
  97.             c_col++;
  98.         }
  99.     }
  100.     else if (wang_pc)
  101.     {
  102.         if (tthue == CTEXT)
  103.             attribute = 0x00;
  104.         else
  105.             attribute = 0x02;
  106.  
  107.         x = stringsize;
  108.         screen = (unsigned short *) WANG_CHARACTER_SCREEN;
  109.         screen += ((row - 1) * 80) + startcol - 1;
  110.         outp (SCREEN_PORT, 01);
  111.         while (x--)
  112.         {
  113.             *screen = (*string++ << 8) | attribute;
  114.             screen++;
  115.         }
  116.         outp (SCREEN_PORT, 00);
  117.     }
  118. }
  119.  
  120. /* 
  121. *   return with a TRUE if key was struck.
  122. */
  123. int     ttkeyready ()
  124. {
  125.     int    cnt;
  126.  
  127.     if (last_key != 0)
  128.         return (1);
  129.  
  130.     last_key = bdos (6, 0xff, 0);
  131.     last_key &= 0xff;
  132.     if (last_key == 0)
  133.         return (0);
  134.     else
  135.         return (1);
  136. }
  137.  
  138. /*
  139. * Read character.
  140. */
  141. int     ttgetc ()
  142. {
  143.     int     c;
  144.     if (last_key != 0)
  145.     {
  146.         c = last_key;
  147.         last_key = 0;
  148.         return (c);
  149.     }
  150.     ttcooked ();
  151.     c = (bdos (7, 0, 0) & 0xFF);
  152.     ttraw ();
  153.     return (c);
  154. }
  155.  
  156. /* disable nasty cntrl-c during disk io!
  157. */
  158. void ttraw ()
  159. {
  160.     union REGS inregs, outregs;
  161.  
  162.     inregs.h.al = 1;
  163.     inregs.h.ah = 0x33;
  164.     inregs.h.dl = 0;
  165.     intdos (&inregs, &outregs);
  166.     /*
  167.     cntrlcoff();
  168. */
  169. }
  170.  
  171. /* re enable cntrl-c for keyboard 
  172. */
  173. void ttcooked ()
  174. {
  175.     union REGS inregs, outregs;
  176.  
  177.     inregs.h.al = 1;
  178.     inregs.h.ah = 0x33;
  179.     intdos (&inregs, &outregs);
  180.     inregs.h.dl = 1;
  181.     /*
  182.     cntrlcon();
  183. */
  184. }
  185.  
  186. /* switch physical monitors
  187. */
  188. static char str[] =
  189. {
  190.     0x1b, '/', 1, 's'
  191. };
  192.  
  193. void     set_crt_type ()
  194. {
  195.     char    active_screen;
  196.  
  197.     active_screen = getscreenstate ();
  198.     slot = active_screen & 0x0f;
  199.     scr_type = (active_screen & 0x70) >> 4;
  200.     video_port = 0x1010 | (slot << 8);
  201. }
  202. #endif
  203.